package com.itranswarp.learnjava;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.function.LongSupplier;
import java.util.stream.LongStream;
import java.util.stream.Stream;

/**
 * Learn Java from https://www.liaoxuefeng.com/
 *
 * @author mikelv
 */
public class Main {

	public static void main(String[] args) throws IOException {
		LongStream fib = LongStream.generate(new FibSupplier());
		// 打印Fibonacci数列：1，1，2，3，5，8，13，21...
		fib.limit(10).forEach(System.out::println);
	}
}

class FibSupplier implements LongSupplier {

	int x = 0;
	int y = 1;
	int sum = 0;
	@Override
	public long getAsLong() {
		sum = x + y;
		x = y;
		y = sum;
		return x;
	}
}
